package com.zhu.storesmanager.models;

import com.zhu.storesmanager.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class PromoterInfoItem {
    public long mDBid = -1; //数据库ID
    public String mPromoterId; //促销员ID
    public String mPromoterName; //促销员名字
    public int mInpost; //在岗情况
    public int mImage; //形象
    public int mStatus; //状态
    public String mBadReason; //不好原因
    public int mCheck; //考勤
    public int mTemporary; //临时情况
    public String mTempName; //临时促销员名字
    public String mTempTel; //临时促销员电话
    public String mNotPostReason;  //不在岗原因
    public String mProblem; //促销员问题
    public Bitmap mPhoto; //照片

    /**
     * 设置图片数据
     * @param data 图片数据
     */
    public void setImageData(byte[] data){
        if(data != null && data.length > 0){
            mPhoto = BitmapFactory.decodeByteArray(data, 0, data.length);
        }
    }

    /**
     * 拷贝数据
     * @param data 数据源
     * @param context 上下文
     */
    public void copyFrom(Context context, SyncModel.DataVisitContentPromoter data){
    	mPromoterId = data.PromoterCode;
    	mPromoterName = data.PromoterName;
    	mBadReason = data.NotGoodReason;
    	mTempName = data.TempName;
    	mTempTel = data.TempMobile;
    	mNotPostReason = data.OffDutyReason;
    	mProblem = data.Question;
    	mInpost = getDutyStatusIndex(context, data.DutyStatus);
    	mImage = getAppearanceIndex(context, data.Appearance);
    	mStatus = getPerformanceIndex(context, data.Performance);
    	mCheck = getAttendanceIndex(context, data.Attendance);
    	mTemporary = getTemporaryPromoterIndex(context, data.TemporaryPromoter);
    }

    /**
	 * 在岗情况
	 * @param text 文本
	 * @param context Context
	 */
	public int getDutyStatusIndex(Context context, String text){
		if(text != null){
			if(context.getString(R.string.dialog_yes).equals(text)){//是
				return 0;
			}else if(context.getString(R.string.dialog_no).equals(text)){ //否
				return 1;
			}else if(context.getString(R.string.promoter_select_xiu).equals(text)){//休
				return 2;
			}		
		}
		return -1;
	}

	/**
	 * 形象
	 * @param text 文本
	 * @param context Context
	 */
	public int getAppearanceIndex(Context context, String text){
		if(text != null){
			if(context.getString(R.string.promoter_select_hao).equals(text)){//好
				return 0;
			}else if(context.getString(R.string.promoter_select_jiaohao).equals(text)){ //较好
				return 1;
			}else if(context.getString(R.string.promoter_select_cha).equals(text)){//差
				return 2;
			}		
		}
		return -1;
	}

	/**
	 * 状态
	 * @param text 文本
	 * @param context Context
	 */
	public int getPerformanceIndex(Context context, String text){
		if(text != null){
			if(context.getString(R.string.promoter_select_hao).equals(text)){//好
				return 0;
			}else if(context.getString(R.string.promoter_select_buhao).equals(text)){ //不好
				return 1;
			}	
		}
		return -1;
	}

	/**
	 * 考勤
	 * @param text 文本
	 * @param context Context
	 */
	public int getAttendanceIndex(Context context, String text){
		if(text != null){
			if(context.getString(R.string.promoter_select_quanqin).equals(text)){//全勤
				return 0;
			}else if(context.getString(R.string.promoter_select_bingjia).equals(text)){ //病假
				return 1;
			}else if(context.getString(R.string.promoter_select_shijia).equals(text)){ //事假
				return 2;
			}else if(context.getString(R.string.promoter_select_xiu).equals(text)){ //休
				return 3;
			}else if(context.getString(R.string.promoter_select_chan).equals(text)){ //产假
				return 4;
			}
		}
		return -1;
	}

	/**
	 * 临促情况
	 * @param text 文本
	 * @param context Context
	 */
	public int getTemporaryPromoterIndex(Context context, String text){
		if(text != null){
			if(context.getString(R.string.dialog_yes).equals(text)){//是
				return 0;
			}else if(context.getString(R.string.dialog_no).equals(text)){ //否
				return 1;
			}else if(context.getString(R.string.promoter_select_wu).equals(text)){ //无
				return 2;
			}
		}
		return -1;
	}
}
